package com.hippy.erya.modular.erya;

import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.hippy.erya.base.pojo.page.LayuiPageFactory;
import com.hippy.erya.base.pojo.page.LayuiPageInfo;
import com.hippy.erya.impl.MessageServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import reactor.core.publisher.Mono;

import javax.websocket.server.PathParam;

@Slf4j
@Controller
@RequestMapping("/erya/message")
public class MessageController extends BaseController {

    @Autowired
    private MessageServiceImpl messageService;

    @RequestMapping(value = "/messageSetting")
    public String message() {
        return "/erya/message/message_setting.html";
    }

    @RequestMapping("/queryAll")
    @ResponseBody
    public Mono<LayuiPageInfo> queryByPage(@PathParam("page") Long page, @PathParam("limit") int limit) {
        return Mono.just(LayuiPageFactory.createPageInfo(messageService.queryByPage(page, limit)));
    }

    @RequestMapping("/readMessage")
    @ResponseBody
    public ResponseData readMessage(String id) {
        String[] idArray = StringUtils.split(id, ",");
        messageService.updateMessage(idArray);
        return ResponseData.success();
    }

}
